package com.tm;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.tm.controller.InstrumentController;

@SuppressWarnings("serial")
public class DeleteInstrument extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//do nothing
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		try {
			UserService userService = UserServiceFactory.getUserService();
			if (userService.isUserLoggedIn() && userService.getCurrentUser().getNickname().equals("vahe@andonians.com")) {
				InstrumentController.getInstance().deleteInstrument(req.getParameter("instrumentId"));
				PrintWriter out = resp.getWriter();
				out.println("successfully deleted");
			}
		} catch (Throwable e) {
			PrintWriter out = resp.getWriter();
			out.println("Error: " + e.getMessage());
		}
	}
}
